<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .wrap {
        width: 200px;
        height: 200px;
        background-color: gray;
    }
    
    .box {
        width: 100px;
        height: 100px;
        background-color: red;
    }
</style>

<body>
    <div id="app">
        <!-- stop:阻止事件的冒泡行为 -->
        <!-- 冒泡行为：由里及外依次触发事件的过程 -->
        <div class="wrap" @click="wrapClick">
            <div class="box" @click.stop="boxClick"></div>
        </div>
        <!-- prevent:阻止默认行为 -->
        <a href="https://www.baidu.com/" @click.prevent="hrefClick">百度</a>
        <!-- capture:添加捕获行为 -->
        <!-- 捕获行为：由外及里依次触发事件的过程 -->
        <div class="wrap" @click.capture="wrapClick">
            <div class="box" @click="boxClick"></div>
        </div>
        <!-- .self:事件只在自身触发，阻止自身事件的回调，类似于阻止冒泡 -->
        <div class="wrap" @click.self="wrapClick">
            <!-- 只让wrap触发自己的不让box触发 -->
            <div class="box" @click="boxClick"></div>
        </div>
        <!-- .once:事件只触发一次 -->
        <button @click.once="clickBtn">点击</button>
    </div>
</body>

</html>
<script src="js/vue3.4.21.js"></script>
<script>
    const {
        createApp,
        ref
    } = Vue

    createApp({
        setup() {
            function wrapClick() {
                console.log('点击了灰色wrap盒子');
            }

            function boxClick() {
                console.log('点击了红色box盒子');
            }

            function hrefClick() {
                alert('跳转行为被阻止了')
            }

            function clickBtn() {
                alert('事件被点击了')
            }

            return {
                wrapClick,
                boxClick,
                hrefClick,
                clickBtn
            }

        }
    }).mount('#app')
</script>